import React, {useState} from "react";

import '@/components/editor.less'
import BraftEditor, {EditorState} from 'braft-editor'


interface Props {
  onChange?: (content: string) => void;
  content?: string;

}


const MyEditor: React.FC<Props> = (props) => {
  const {onChange,content} = props
  // @ts-ignore
  const [editorState, setEditorState] = useState<EditorState> ( BraftEditor.createEditorState ( content | null ) );
  const handleChange = (editorState: { toHTML: () => any }) => {
    let html = editorState.toHTML ();
    console.log ( html )
    if (onChange) {
    onChange ( html );
    }
//    setContent ( html );
  };
   // setEditorState ( ContentUtils.insertHTML ( editorState, res?.data?.content ) );
  return (<>     <BraftEditor value={editorState} onChange={handleChange}/></>);
}

export default MyEditor
